<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
  <head>
    <title>申购人，编辑我的信息</title>
    <script type="text/javascript">
      Ext.onReady(function(){
        var applicantId = <%= session[:applicant_id] %>
        var departmentDS = new Ext.data.Store({
          proxy:new Ext.data.HttpProxy({url:'/department/getDepartments'}),
          autoLoad:true,
          reader:new Ext.data.JsonReader({
          }, [
            {name:'name'},
            {name:'id'}
          ])
        });
        var editApplicantForm=new Ext.form.FormPanel({
          width:600,
          //labelAlign: 'top',
          url:'/applicant/updateInformation',
          buttonAlign:'center',
          autoHeight:true,
          fileUpload: true,
          bodyStyle: 'padding:5px',
          labelWidth:100,
          waitMsgTarget: true,
          frame: true,
          reader:new Ext.data.JsonReader({
          },[
            {name:'id'},
            {name:'login_id'},
            {name:'name'},
            {name:'mobile'},
            {name:'phone'},
            {name:'email'},
            {name:'department_id'}
          ]),
          items:[{
              layout:'column',
              items:[{
                  columnWidth:.5,
                  layout:'form',
                  labelAlign: 'top',
                  items:[{
                      xtype:'hidden',
                      name:'id'
                    },{
                      xtype:'textfield',
                      fieldLabel: '我的编号',
                      name: 'login_id',
                      allowBlank:false,
                      disabled:true,
                      anchor:'90%'
                    },{
                      xtype:'textfield',
                      fieldLabel: '移动电话',
                      name: 'mobile',
                      allowBlank:false,
                      anchor:'90%'
                    },{
                      xtype:'textfield',
                      fieldLabel: 'Email',
                      name: 'email',
                      allowBlank:false,
                      anchor:'90%'
                    }]
                },{
                  columnWidth:.5,
                  layout:'form',
                  labelAlign: 'top',
                  items:[{
                      xtype:'textfield',
                      fieldLabel: '我的姓名',
                      name:'name',
                      allowBlank:false,
                      anchor:'90%'
                    },{
                      xtype:'textfield',
                      fieldLabel: '固定电话',
                      name: 'phone',
                      allowBlank:false,
                      anchor:'90%'
                    },{
                      xtype:'combo',
                      store: departmentDS,
                      displayField:'name',
                      hiddenName:'department_id',
                      valueField:'id',
                      typeAhead: true,
                      allowBlank:false,
                      disabled:true,
                      minChars:1,
                      anchor: '90%',
                      mode: 'remote',
                      fieldLabel:'所属部门',
                      forceSelection: true,
                      triggerAction: 'all',
                      emptyText:'请选择所属部门.....',
                      selectOnFocus:true
                    }]
                }]
            }],
          buttons:[{
              id:'save',
              text:'确定',
              handler: function(){
                            
                // check form value
                if (editApplicantForm.form.isValid()) {
                  Ext.getCmp('save').setDisabled(true);
                  editApplicantForm.form.submit({
                    method: 'post',
                    waitMsg: '正在保存个人信息...',
                    success: function(result, response){
                      if (response.result.info == "success") {
                        //添加成功后，隐藏窗口，并刷新Grid
                        editApplicantWin.destroy();
                      }
                      else {
                        Ext.getCmp('save').setDisabled(false);
                        Ext.MessageBox.alert('消息', response.result.info);
                      }
                    },
                    failure: function(result, response){
                      Ext.getCmp('save').setDisabled(false);
                      Ext.MessageBox.alert('提示', result.responseText);
                    }
                  });
                }
                else {
                  Ext.MessageBox.alert('错误提示', '请按要求填写必输选项.');
                }
              }
            },{
              text:'取消',
              handler:function(){
                editApplicantWin.destroy();
              }
            }]
        });
        editApplicantForm.form.load({
          url: '/applicant/edit?id=' + applicantId,
          success: function(form, action){
          },
          failure: function(form, action){
            Ext.MessageBox.alert('提示信息', '信息加载失败');
          }
        });
        editApplicantForm.render('edit_applicant_form');
      })
    </script>
  </head>
  <body>
    <div id="edit_applicant_form"></div>
  </body>
</html>
